//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.aidong.dao.wills;

import com.aidong.dao.wills.BaseDao;
import com.aidong.model.wills.ContractInfo;
import com.aidong.model.wills.MemberAmortize;
import java.util.Date;
import java.util.List;
import org.springframework.stereotype.Repository;

@Repository
public class MemberAmortizeDao extends BaseDao<MemberAmortize, Integer> {
	public MemberAmortizeDao() {
	}

	public List<MemberAmortize> getShopSum(String period) {
		String sql = "select c.shopCode, sum(a.amount) amount\nfrom MemberAmortize a inner join MemberContract c on a.contractCode=c.contractCode\nwhere a.period=:p1 group by c.shopCode\norder by c.shopCode";
		return this.queryListBySql(MemberAmortize.class, sql, new Object[]{period});
	}

	public List<ContractInfo> getAmortizeSum(String period) {
		String sql = "select c.shopCode, sum(case when period=:p1 then amount else 0 end) factPrice, sum(a.amount) totalPrice\nfrom MemberAmortize a inner join MemberContract c on a.contractCode=c.contractCode\ngroup by c.shopCode order by c.shopCode";
		return this.queryListBySql(ContractInfo.class, sql, new Object[]{period});
	}

	public List<ContractInfo> getAmortizeDetail(String period, Date dateFrom, Date dateTo) {
		String sql = "Select c.ShopCode,c.ContractCode,c.MemberCode,c.SaleType,c.SaleDate,c.BeginTime,c.EndTime,c.EffectiveDate\n,ct.TypeId type,c.CardType,c.TotalCount,c.RestCount,c.EarnestAmount+c.PayAmount PayAmount,c.InAmount,c.OutAmount\n,case when c.SaleDate<\'2015-06-01\' then FixedFee else isnull(ct.AmortizeFee1,0)+isnull(ct.AmortizeFee2,0)+isnull(ct.AmortizeFee3,0)+isnull(ct.AmortizeFee4,0) end FixedFee\n,(Select IsNull(Sum(Amount),0) From MemberAmortize a Where Period=:p1 and a.ContractCode=c.ContractCode) factPrice\n,(Select IsNull(Sum(Amount),0) From MemberAmortize a Where a.ContractCode=c.ContractCode) totalPrice\nFrom MemberContract c Left Join CardTypeCode ct On c.CardType = ct.Code\nWhere c.status=\'1\' and c.ShopCode<>\'Test\' and c.SaleDate>=:p2 and c.SaleDate<:p3\norder by c.SaleDate";
		return this.queryListBySql(ContractInfo.class, sql, new Object[]{period, dateFrom, dateTo});
	}
}
